package com.sgb.kjwl.view.widget.member;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.businessmanagement.CompanyEntity;
import com.sgb.kjwl.view.ui.adapter.self.CompanyChangeAdapter;
import com.sgb.kjwl.view.widget.MaxHeightRecyclerView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class CompanyChoosePopWindow extends BasePopWindow<CompanyEntity> {
    private CompanyChoosePopWindow.DialogClickCallBack dialogClickCallBack;
    private CompanyChangeAdapter goodsTypeAdapter;

    public CompanyChoosePopWindow(Context context) {
        super(context);
    }


    @Override
    protected int popLayout() {
        return R.layout.popwindow_self_fragment_company;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        View bgGrayLayout = holder.getPop().findViewById(R.id.bg_pop_gray_layout);
        RecyclerView recyclerView = holder.getPop().findViewById(R.id.goods_type_list);
        goodsTypeAdapter = new CompanyChangeAdapter(holder.getPop().getContext(), null);
        goodsTypeAdapter.setItemSelect(true);
        goodsTypeAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new GridLayoutManager(holder.getPop().getContext(), 1));
        recyclerView.setAdapter(goodsTypeAdapter);
        goodsTypeAdapter.setOnItemClick(new AdapterOnItemClick<CompanyEntity>() {
            @Override
            public void onItemClick(CompanyEntity provinceEntity, int position) {
                dialogClickCallBack.onItemClick(provinceEntity, position);
            }
        });
        setBgView(bgGrayLayout);
    }

    public void setData(List<CompanyEntity> list) {
        goodsTypeAdapter.setDatas(list);
    }

    public void setItem(int position) {
        goodsTypeAdapter.setDefItem(position);
    }

    public interface DialogClickCallBack {
        void onItemClick(CompanyEntity provinceEntity, int position);
    }

    public CompanyChoosePopWindow setDialogClickCallBack(CompanyChoosePopWindow.DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }

    @Override
    public void showPopwindow0(View view) {
        super.showPopwindow(view, false, 0, 30);
    }

}
